﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using GBlason.ViewModel;
using GBlason.ViewModel.Control;
using GBlason.ViewModel.General;

namespace GBlason.Common.Converter
{
    public class DoubleToZoomLevel : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var fileParam = parameter as GbsFileViewModel;

            if (value is Double && fileParam != null)
                return fileParam.AvailableZoom.FirstOrDefault(az => az.Value == (double)value);
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var zparam = value as ZoomLevelViewModel;
            if (zparam != null)
                return zparam.Value;
            return (double) 0;
        }
    }
}
